﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using TaiwuModFramework.Common.Abstract;
using TaiwuModFramework.Common.Base;

namespace TaiwuModFramework.Common.Info {
    public class ServiceInfo {

        public string ModIdStr { get; private set; }
        public string ServiceName { get; private set; }
        private MethodInfo ServiceMethod;
        private AService ServiceObj;
        public bool IsComp { get; private set; }

        public ServiceInfo(string modIdStr, string serviceName, MethodInfo method, AService serviceObj) {
            ModIdStr = modIdStr;
            ServiceName = serviceName;
            this.ServiceObj = serviceObj;
            this.ServiceMethod = method;
            IsComp = serviceObj is BaseTaiwuComp;
        }


        public object Invoke(object[] args) {
            if(IsComp && (!((BaseTaiwuComp)ServiceObj).CompEnable)) {
                // 组件未启用的情况下，报错
                throw new System.Exception(string.Format("组件{0}未启用，无法提供服务", ServiceObj.GetType().FullName));
            }
            return ServiceMethod.Invoke(ServiceObj, args);
        }
    }
}
